package com.heyqing.topic.IsPalindrome_0125;

/**
 * ClassName:IsPalindrome
 * Package:com.heyqing.topic.IsPalindrome_0125
 * Description:
 *
 * @Date:2024/9/16
 * @Author:Heyqing
 */
public class IsPalindrome {
    public boolean isPalindrome(String s) {
        String regexStr = s.replaceAll("[^a-zA-Z0-9]+", "").toLowerCase();
        int len = regexStr.length();
        int loop = (len & 1) == 1 ? len / 2 : (len + 1) / 2;
        for (int i = 0; i < loop; i++) {
            if (regexStr.charAt(i) != regexStr.charAt(len - i - 1)) return false;
        }
        return true;
    }
}
